package zelix.hack.hacks;

import zelix.gui.clickguis.gishcode.ClickGuiScreen;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.Wrapper;
import org.lwjgl.input.Keyboard;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import zelix.utils.Utils;

public class GuiWalk extends Hack {


	public GuiWalk() {
		super("GuiWalk", HackCategory.MOVEMENT);
	
	}

	@Override
	public String getDescription() {
		return "Allows you to walk while the gui is open.";
	}

	/*
	 * @Override public void onInputUpdate(InputUpdateEvent event) { if
	 * (!mode.getMode("AAC").isToggled()) { return; } if
	 * (!(Wrapper.INSTANCE.mc().currentScreen instanceof GuiContainer) &&
	 * !(Wrapper.INSTANCE.mc().currentScreen instanceof ClickGuiScreen)) return;
	 * 
	 * if (Wrapper.INSTANCE.player().onGround &&
	 * Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindJump.getKeyCode())) {
	 * Wrapper.INSTANCE.player().jump(); } if
	 * (Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindRight.getKeyCode()))
	 * return;
	 * 
	 * super.onInputUpdate(event); }
	 */

	@Override
	public void onClientTick(ClientTickEvent event) {
		
		if (!(Wrapper.INSTANCE.mc().currentScreen instanceof GuiContainer)
				&& !(Wrapper.INSTANCE.mc().currentScreen instanceof ClickGuiScreen))
			return;

		double speed = 0.05;

		if (!Wrapper.INSTANCE.player().onGround)
			speed /= 4.0;

		handleJump();
		handleForward(speed);

		if (!Wrapper.INSTANCE.player().onGround)
			speed /= 2.0;

		handleBack(speed);
		handleLeft(speed);
		handleRight(speed);

		super.onClientTick(event);
	}

	void moveForward(double speed) {
		float direction = Utils.getDirection();
		Wrapper.INSTANCE.player().motionX -= (double) (MathHelper.sin(direction) * speed);
		Wrapper.INSTANCE.player().motionZ += (double) (MathHelper.cos(direction) * speed);
	}

	void moveBack(double speed) {
		float direction = Utils.getDirection();
		Wrapper.INSTANCE.player().motionX += (double) (MathHelper.sin(direction) * speed);
		Wrapper.INSTANCE.player().motionZ -= (double) (MathHelper.cos(direction) * speed);
	}

	void moveLeft(double speed) {
		float direction = Utils.getDirection();
		Wrapper.INSTANCE.player().motionZ += (double) (MathHelper.sin(direction) * speed);
		Wrapper.INSTANCE.player().motionX += (double) (MathHelper.cos(direction) * speed);
	}

	void moveRight(double speed) {
		float direction = Utils.getDirection();
		Wrapper.INSTANCE.player().motionZ -= (double) (MathHelper.sin(direction) * speed);
		Wrapper.INSTANCE.player().motionX -= (double) (MathHelper.cos(direction) * speed);
	}

	void handleForward(double speed) {
		if (!Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindForward.getKeyCode()))
			return;
		moveForward(speed);
	}

	void handleBack(double speed) {
		if (!Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindBack.getKeyCode()))
			return;
		moveBack(speed);
	}

	void handleLeft(double speed) {
		if (!Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindLeft.getKeyCode()))
			return;
		moveLeft(speed);
	}

	void handleRight(double speed) {
		if (!Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindRight.getKeyCode()))
			return;
		moveRight(speed);
	}

	void handleJump() {
		if (Wrapper.INSTANCE.player().onGround
				&& Keyboard.isKeyDown(Wrapper.INSTANCE.mcSettings().keyBindJump.getKeyCode()))
			Wrapper.INSTANCE.player().jump();
	}

}
